package com.chilly.other.collection;

import java.util.Objects;

/**
 * @Author cuihaiyan
 * @Create_Time 2020-11-29 09:42
 * @Description: TreeSet的验证
 */
public class Stu implements Comparable{
    private String name;
    private Integer age;

    public Stu() {
    }

    public Stu(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Stu stu = (Stu) o;
        return name.equals(stu.name) && age.equals(stu.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public int compareTo(Object o) {
        Stu stu = (Stu) o;
        if (age > stu.age){
            return 1;
        }
        return 0;
    }

    @Override
    public String toString() {
        return "Stu{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
